/ Assembly List / LJCNetCommon / NetString / GetDelimitedAndIndexes

Namespace - LJCNetCommon


Parameters
text - The text value.
beginDelimiter - The beginning delimiter.
beginIndex - The begin index.
endIndex - The end index.
startIndex - The starting index.
endDelimiter - The ending delimiter.

Returns

The string between the specified delimiters.

Syntax

C#
public static String GetDelimitedAndIndexes(String text, String beginDelimiter, out Int32& beginIndex, out Int32& endIndex, Int32& startIndex, String endDelimiter = null)

Get the delimited string begin and end index.

Example

C#
using LJCNetCommon;
        
// Get the delimited string begin and end index.
private static void GetDelimitedAndIndexes()
{
  // Get text that has different begin and end delimiter.
  var source = "<summary>This is some text.</summary>";
  int startIndex = 0;
  var beginDelimiter = "<summary>";
  var endDelimiter = "</summary>";
  var text = NetString.GetDelimitedAndIndexes(source, beginDelimiter
    , out int beginIndex, out int endIndex, ref startIndex, endDelimiter);
  // text = "This is some text.";
  // beginIndex = 0;
  // endIndex = 27;
  // startIndex = -1;

  // Get text that has the same begin and end delimiter.
  // The endDelimiter is not specified or null.
  source = "|This is some text.|";
  startIndex = 0;
  beginDelimiter = "|";
  text = NetString.GetDelimitedAndIndexes(source, beginDelimiter
    , out beginIndex, out endIndex, ref startIndex);
  // text = "This is some text.";
  // beginIndex = 0;
  // endIndex = 19;
  // startIndex = -1;

  // Get text that has no end delimiter.
  source = "|This is some text.";
  startIndex = 0;
  beginDelimiter = "|";
  text = NetString.GetDelimitedAndIndexes(source, beginDelimiter
    , out beginIndex, out endIndex, ref startIndex, "#NoDelimiter");
  // text = "This is some text.";
  // beginIndex = 0;
  // endIndex = 19;
  // startIndex = -1;

  // Get delimited text where the delimiters occur multiple times.
  source = "|This is some text.| |and some more here.|";
  startIndex = 0;
  beginDelimiter = "|";
  while (startIndex > -1)
  {
    text = NetString.GetDelimitedAndIndexes(source, beginDelimiter
      , out beginIndex, out endIndex, ref startIndex);
    // First time: text = "This is some text.";
    // beginIndex = 0;
    // endIndex = 19;
    // startIndex = 20;
    // Second time: text = "and some more here.";
    // beginIndex = 21;
    // endIndex = 41;
    // startIndex = -1
  }
}

Copyright © Lester J. Clark and Contributors.
Licensed under the MIT License.